package com.ruoyi.pcj.service.impl;

import java.util.Arrays;
import java.util.List;

import com.mashuai.utils.base.MsEmptyUtils;
import com.mashuai.utils.toolkit.core.msMp.MsDb;
import com.mashuai.utils.toolkit.core.msValidation.annotation.MsCheckParams;
import com.ruoyi.basis.service.MsBaseServiceImpl;
import org.springframework.stereotype.Service;
import com.ruoyi.pcj.mapper.PcjHobbyMapper;
import com.ruoyi.pcj.domain.PcjHobby;
import com.ruoyi.pcj.service.IPcjHobbyService;

/**
 * 兴趣Service业务层处理
 *
 * @author ms
 * @date 2024-02-03
 */
@Service
public class PcjHobbyServiceImpl extends MsBaseServiceImpl<PcjHobbyMapper, PcjHobby> implements IPcjHobbyService {

    /**
     * 查询兴趣
     *
     * @param id 兴趣主键
     * @return 兴趣
     */
    @Override
    public PcjHobby selectPcjHobbyById(String id) {
        PcjHobby entity = MsDb.getById(id, PcjHobby.class);
        return entity;
    }

    /**
     * 查询兴趣列表
     *
     * @param pcjHobby 兴趣
     * @return 兴趣
     */
    @MsCheckParams
    @Override
    public List<PcjHobby> selectPcjHobbyList(PcjHobby pcjHobby) {
        return baseMapper.selectPcjHobbyList(pcjHobby);
    }

    /**
     * 新增兴趣
     *
     * @param pcjHobby 兴趣
     * @return 结果
     */
    @Override
    public Boolean insertPcjHobby(PcjHobby pcjHobby) {
        Boolean success = this.insertData(pcjHobby);
        return success;
    }

    /**
     * 修改兴趣
     *
     * @param pcjHobby 兴趣
     * @return 结果
     */
    @Override
    public Boolean updatePcjHobby(PcjHobby pcjHobby) {
        Boolean success = this.updateData(pcjHobby);
        return success;
    }

    /**
     * 批量删除兴趣
     *
     * @param ids 需要删除的兴趣主键
     * @return 结果
     */
    @Override
    public Boolean deletePcjHobbyByIds(String[] ids) {
        Boolean success = this.removeBatchByIds(Arrays.asList(ids));
        return success;
    }

    @Override
    public void batchSaveHobby(List<PcjHobby> hobbyList, String hobbyTypeId) {
        //子表
        if (hobbyList == null || hobbyList.size() == 0) return;
        for (PcjHobby pcjHobby : hobbyList) {
            if (MsEmptyUtils.isNotEmpty(pcjHobby.getId())) {
                this.setDefFieldVal(pcjHobby, false);
            } else {
                pcjHobby.setHobbyTypeId(hobbyTypeId);
                this.setDefFieldVal(pcjHobby, true);
            }
        }
        MsDb.saveOrUpdateBatch(hobbyList);
    }
}
